package com.example.swagger.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // 设置URL的授权问题
        // 多个条件取交集
        http.authorizeRequests()
                // 匹配 / 控制器  permitAll() 不需要被认证就可以访问
                .antMatchers("/").permitAll()
                .antMatchers("/swagger-resources/**").authenticated()
                .antMatchers("/webjars/**").authenticated()
                .antMatchers("/v2/**").authenticated()
                .antMatchers("/swagger-ui.html/**").authenticated()
                .and().formLogin();

        // 关闭csrf
        http.csrf().disable();

    }
}
